﻿using System;
using System.Collections.Generic;
using KZ.Exception;
using KZ.Lottery.DAL;
using KZ.Lottery.Entities;
using KZ.Lottery.Resources;

namespace KZ.Lottery.BLL
{
    public class ResultBLL
    {
        ResultDAL _ResultDAL = new ResultDAL();

        public static Result GetResult(string resultID)
        {
            return ResultDAL.GetResult(resultID);
        }

        public static List<Result> GetResultList(string channelID, DateTime from, DateTime to)
        {
            return ResultDAL.GetResultList(channelID, from, to);
        }

        public static bool DeleteResult(string resultID)
        {
            return ResultDAL.DeleteResult(resultID);
        }

        public static bool ApproveResult(List<Result> resultList)
        {
            return ResultDAL.ApproveResult(resultList);
        }

        public bool InsertResult(Result result)
        {
            ValidateData(result);
            return _ResultDAL.InsertResult(result);
        }

        public bool UpdateResult(Result result)
        {
            ValidateData(result);
            return _ResultDAL.UpdateResult(result);
        }

        private void ValidateData(Result result)
        {
            if (String.IsNullOrEmpty(result.Head)) { throw new BusinessLogicException(KZ_Message.BLM_ERR_HEADRESULT_REQUIRE); }
            if (String.IsNullOrEmpty(result.Tail)) { throw new BusinessLogicException(KZ_Message.BLM_ERR_TAILRESULT_REQUIRE); }
            if (result.Head.Length != 2 || result.Tail.Length != 2) { throw new BusinessLogicException(KZ_Message.BLM_ERR_RESULT_2NUMBER); }
        }
    }
}